/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86131
 * Date: 2023-11-14
 * Time: 15:15
 */
public class test4 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8,9};
        int[] copy = copyOfRange(arr, 3, 7);
        for(int i =0;i < copy.length;i++){
            System.out.print(copy[i]+" ");
        }
    }

    //将数组arr从索引from开始,到索引to结束的元素复制到新数组中
    public static int[] copyOfRange(int[] arr,int from,int to){
        //1.定义数组
        //动态数组,不知道几个元素
        int[] newArr = new int[to-from];
        int j = 0;
        //2.把原始数组arr中的from到to上的对应元素,直接拷贝到newArr中
        for(int i = from;i < to;i++){
            newArr[j] = arr[i];
            j++;
        }
        return newArr;
    }
}
